package app.fugema.shop.main.order.vm;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import app.fugema.shop.main.order.model.OrderRefundModelResult;
import app.fugema.shop.main.order.model.RefundApplyParams;
import app.fugema.shop.main.order.model.RefundDetailResult;
import app.fugema.shop.main.order.model.RefundOrdersResult;

import com.base.common.netBeanPackage.BaseApiResult;
import com.base.common.netBeanPackage.LiveDataWrapper;
import com.base.common.utils.UIUtils;
import com.base.common.viewmodel.BaseViewModel;
import app.fugema.shop.http.HttpService;
import app.fugema.shop.main.order.model.RefundProcessDetailResult;
import app.fugema.shop.main.setting.model.UploadPicResult;
import retrofit2.http.Query;

import java.util.HashMap;
import java.util.Map;

public class OrderAfterSaleVM extends BaseViewModel
{
    //售后

    public OrderAfterSaleVM(@NonNull Application application) {
        super(application);
    }

    /**
     *  获取 准备提交退款的 订单信息
     * @param orderId
     * @param userKey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<OrderRefundModelResult>> getOrderRefundModel(Long orderId, String itemId,String userKey)
    {
        //@Query("id") long orderId , @Query("userkey") String userkey
        Map<String, Object> map = new HashMap<>();
        map.put("id", orderId);
        if(UIUtils.isNotEmpty( itemId ))
        {
            map.put("itemId",itemId);
        }
        map.put("userKey",userKey);
        return send(HttpService.getHttpServer().getOrderRefundModel(map));
    }


    /**
     *  提交 申请退款
     * @param applyParams
     * @return
     */
    public MutableLiveData<LiveDataWrapper<BaseApiResult>> applyOrderRefund(RefundApplyParams applyParams)
    {
        /*
        orderid=2021070184447823&  （退款退货  orderitemId 264）
        refundtype=1&    （2 退款退货）
        returnquantity=0&
        amount=195.00&
        reason=商品破损&
        contactperson=梁心颐&
        contactcellPhone=13125043081&
        refundpaytype=3&     (1 原路返回)
        reasondetail=测试提交退款说明&
        userkey=Zi&
        certpic1=/temp/20210702172626845261.png
        certpic2 /temp/20210810095754442211.png
        */
        Map<String, Object> map = new HashMap<>();
        if(UIUtils.isNotEmpty(applyParams.getOrderid()))
        {
            map.put("orderid", applyParams.getOrderid());
        }
        if(UIUtils.isNotEmpty(applyParams.getItemId()))
        {
            map.put("orderitemid", Integer.parseInt(applyParams.getItemId()));
        }
        if (UIUtils.isNotEmpty(applyParams.getRefundtype()))
        {
            map.put("refundtype", applyParams.getRefundtype());
        }
        if (UIUtils.isNotEmpty(applyParams.getReturnquantity()))
        {
            map.put("returnquantity", applyParams.getReturnquantity());
        }
        if (UIUtils.isNotEmpty(applyParams.getAmount()))
        {
            map.put("amount", applyParams.getAmount());
        }
        if (UIUtils.isNotEmpty(applyParams.getReason()))
        {
            map.put("reason", applyParams.getReason());
        }
        if (UIUtils.isNotEmpty(applyParams.getContactperson()))
        {
            map.put("contactperson", applyParams.getContactperson());
        }

        if (UIUtils.isNotEmpty(applyParams.getContactcellPhone()))
        {
            map.put("contactcellPhone", applyParams.getContactcellPhone());
        }
        if (UIUtils.isNotEmpty(applyParams.getRefundpaytype()))
        {
            map.put("refundpaytype", applyParams.getRefundpaytype());
        }
        if (UIUtils.isNotEmpty(applyParams.getReasondetail()))
        {
            map.put("reasondetail", applyParams.getReasondetail());
        }
        if (UIUtils.isNotEmpty(applyParams.getCertpic1()))
        {
            map.put("certpic1", applyParams.getCertpic1());
        }
        if (UIUtils.isNotEmpty(applyParams.getCertpic2()))
        {
            map.put("certpic2", applyParams.getCertpic2());
        }
        if (UIUtils.isNotEmpty(applyParams.getCertpic3()))
        {
            map.put("certpic3", applyParams.getCertpic3());
        }
        map.put("userkey", applyParams.getUserkey());
        return send(HttpService.getHttpServer().applyOrderRefund(map));
    }

    /**
     * 退款单详情
     * @param refundOrderId
     * @param userkey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<RefundDetailResult>> refundOrderDetail(int refundOrderId, String userkey)
    {
        return send(HttpService.getHttpServer().getRefundOrderDetail(refundOrderId, userkey));
    }

    /**
     * 退款列表
     * @param pn
     * @param pageSize
     * @param userKey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<RefundOrdersResult>> refundOrderList(int pn, int pageSize , String userKey)
    {
        return send(HttpService.getHttpServer().getRefundOrderList(pn, pageSize,userKey));
    }

    /**
     * 退款操作流程详情
     * @param refundOrderId
     * @param userkey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<RefundProcessDetailResult>> refundProcessDetail(int refundOrderId, String userkey)
    {
        return send(HttpService.getHttpServer().refundProcessDetail(refundOrderId,userkey));
    }

    /**
     *  上传图片
     * @param picBase64Str
     * @return
     */
    public MutableLiveData<LiveDataWrapper<UploadPicResult>> upLoadPIc(String picBase64Str)
    {
        return send(HttpService.getHttpServer().upLoadPIc(picBase64Str));
    }
}
